package com.qingke.hibernate.dao;

import java.sql.Time;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.query.Query;

import com.qingke.hibernate.bean.CourseSet;

public class CourseSetDAO extends SystemDAO{

	public CourseSetDAO(Session session) {
		super(session);
	}
	public List<CourseSet> list(){
		Query<CourseSet> query=session.createQuery("from CourseSet", CourseSet.class);
		return query.getResultList();
	}
	public CourseSet getCourseSetById(int id){
		Query<CourseSet> query=session.createQuery("from CourseSet where id=:id", CourseSet.class);
		query.setParameter("id",id);
		return query.getSingleResult();
	}
	public List<CourseSet> getCourseSetsByCapacity(int capacity){
		Query<CourseSet> query=session.createQuery("from CourseSet where capacity=:capacity", CourseSet.class);
		query.setParameter("capacity",capacity);
		return query.getResultList();
	}
	public List<CourseSet> getCourseSetsHaveMargin(){
		Query<CourseSet> query=session.createQuery("from CourseSet where margin>0", CourseSet.class);
		return query.getResultList();
	}
	public List<CourseSet> getCourseSetsNoMargin(){
		Query<CourseSet> query=session.createQuery("from CourseSet where margin=0", CourseSet.class);
		return query.getResultList();
	}
	public List<CourseSet> getCourseSetsByClassTime(Time classTime){
		Query<CourseSet> query=session.createQuery("from CourseSet where class_time=:classTime", CourseSet.class);
		query.setParameter("classTime",classTime);
		return query.getResultList();
	}
	public List<CourseSet> getCourseSetsByTeacherId(int teacherId){
		Query<CourseSet> query=session.createQuery("from CourseSet where teacher_id=:teacherId", CourseSet.class);
		query.setParameter("teacherId",teacherId);
		return query.getResultList();
	}
}
